package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;
import com.moyuer.bsf.domain.model.ConfigItem;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import java.math.BigDecimal;

/**
 * 充值单分录
 *
 * @author: 袁首京<yuanshoujing@gmail.com>
 * 16/4/13
 */
@Entity
@Table(name = "bill_charge_entry")
public class ChargeBillEntry extends AbstractVersionEntity {

    @JSONField(serialize = false)
    @ManyToOne
    protected ChargeBill owner;

    @ManyToOne
    protected GoodsPackage goodsPackage; // 营销活动

    @Column(nullable = false)
    protected BigDecimal price = BigDecimal.ZERO; // 单价

    @Column(nullable = false)
    protected BigDecimal quantity = BigDecimal.ZERO; // 数量

    @Column(nullable = false)
    protected BigDecimal amount = BigDecimal.ZERO; // 金额

	public ChargeBill getOwner() {
        return owner;
    }

    public void setOwner(ChargeBill owner) {
        this.owner = owner;
    }

    public GoodsPackage getGoodsPackage() {
        return goodsPackage;
    }

    public void setGoodsPackage(GoodsPackage goodsPackage) {
        this.goodsPackage = goodsPackage;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getQuantity() {
        return quantity;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
    }

    public BigDecimal getAmount() {
        if (BigDecimal.ZERO.equals(amount)) {
            return price.multiply(quantity);
        }

        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }


}
